﻿namespace Sidvall.Security
{
    public class UserItemCollection : System.Collections.ObjectModel.KeyedCollection<string, UserItem>
    {
        #region Public Members

        #region Add

        public UserItem Add(string name)
        {
            return Add(name, System.DateTime.UtcNow, System.DateTime.UtcNow, null, IdentityStatus.Valid, null);
        }
        public UserItem Add(string name, System.DateTime createdTime, System.DateTime updatedTime, string context, IdentityStatus signInStatus,
            string signInStatusReasonPhrase)
        {
            if (Contains(name))
                return null;
            var item = new UserItem()
            {
                Name = name,
                Context = context,
                CreatedTime = createdTime,
                UpdatedTime = updatedTime,
                UserStatus = signInStatus,
                UserStatusReasonPhrase = signInStatusReasonPhrase,
            };
            Add(item);
            return item;
        }

        #endregion
        #region GetKeyForItem

        protected override string GetKeyForItem(UserItem item)
        {
            if (item == null)
                throw new System.ArgumentNullException("item");
            return item.Name;
        }

        #endregion

        #endregion
        #region Constructors

        public UserItemCollection()
            : base(System.StringComparer.OrdinalIgnoreCase)
        {
        }

        #endregion
    }
}
